﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Phones;
using Domain.MainModule.PhoneTypes;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class PhoneTypeRepositoryTest : RepositoryTestsBase<PhoneType>
    {
       string name = "Phone Type Name";
       
       public override System.Linq.Expressions.Expression<Func<PhoneType, bool>> FilterExpression
        {
            get { return a => a.Name == name; }
        }

        public override System.Linq.Expressions.Expression<Func<PhoneType, Guid>> OrderByExpression
        {
            get { return a => a.TypeId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindPhoneType_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IPhoneTypeRepository repository = new PhoneTypeRepository(context,traceManager);

            //Act
            repository.GetBySpec(null);
        }
			
		[TestMethod()]
        public void FindPhoneType_Invoke_InvalidPhoneTypeNameReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IPhoneTypeRepository repository = new PhoneTypeRepository(context, traceManager);

			string invalidPhoneTypeName = "invalid phone type name";
            PhoneTypeNameSpecification spec = new PhoneTypeNameSpecification(invalidPhoneTypeName);

            //Act
            IEnumerable<PhoneType> result = repository.GetBySpec(spec);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 0);
        }
		
        [TestMethod()]
        public void FindPhoneTypeByPhoneTypeNameInvoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IPhoneTypeRepository repository = new PhoneTypeRepository(context, traceManager);

            PhoneTypeNameSpecification spec = new PhoneTypeNameSpecification(name);

            //Act
            IEnumerable<PhoneType> result = repository.GetBySpec(spec);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
    }
}
